<?php

namespace backend\controllers;

use Yii;
use common\models\MktUser;
use common\models\WxGh;
use common\models\MktUserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;



/**
 * FanController implements the CRUD actions for MktUser model.
 */
class FanController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    public function actionTest()
    {

    $mobile = '123';
//        echo 'before='.Yii::$app->cache->get('SMS-VERIFY-CODEx' . $params['mobile']);

\Yii::$app->cache->set('SMS-VERIFY-CODEx' . $mobile, '34456', 1 * 60);


        echo 'after='.Yii::$app->cache->get('SMS-VERIFY-CODEx' . $mobile);

/*    
        $wxapp =  WxGh::getDefaultGh()->loadWx()->getApplication();
        $menu = $wxapp->menu;
        $menus = $menu->all();
        $menus = $menus['menu']['button'];        
        var_dump($menus);

        yii::$app->sm->sendVerifyCode('15527210477', '12345');       
*/        
       // echo \common\wosotech\Util::generateOid();
        
    }
    
    /**
     * Lists all MktUser models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new MktUserSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        //yii::error(print_r($_GET, true));
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single MktUser model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new MktUser model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new MktUser();
        $model->loadDefaultValues();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect('index');
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing MktUser model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect('index');            
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing MktUser model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the MktUser model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return MktUser the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = MktUser::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
